# -*- encoding : utf-8 -*-
# @Author  :    liaogan
# @Time    :    2022/4/2 10:22
from selenium import webdriver
import time
class TestBaidu():
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(10)
        self.base_url = "http://www.baidu.com/"

    def test_baidu_search(self, search_string):
        self.driver.get(self.base_url + "/")
        self.driver.find_element_by_id("kw").send_keys(search_string)
        self.driver.find_element_by_id("su").click()
        time.sleep(2)
        search_results = self.driver.find_element_by_xpath('//*[@id="1"]/h3/a').get_attribute('innerHTML')
        print(search_results)
        if search_string in search_string:
            print('test pass')
        else:
            print('test fail')

    def tearDown(self):
        time.sleep(2)
        print('我暂停运行了2秒')
        self.driver.quit()

if __name__ == '__main__':
    test1=TestBaidu()
    test1.test_baidu_search("Testing")
    test1.tearDown()
